package com.vortex.cloud.sample.easyexcel.kuangshen.poi.read;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Objects;

/**
 * @author 王林
 * @version 1.0
 * @date 2021-10-15 周五
 * @time 12:01
 * @description
 */
public class ReadTestPractice07 {
    public static void main(String[] args) throws IOException {
        String PATH = "H:\\fuTaiPorjects\\backend\\hw-clouc-sample-easyExcel\\";

        //获取文件流
        FileInputStream fileInputStream = new FileInputStream(PATH + "明细表.xls");

        //1-创建一个工作簿，使用excel操作的，这边都可以操作
        Workbook workbook = new HSSFWorkbook(fileInputStream);
        //2-得到表
        Sheet sheet = workbook.getSheetAt(0);

        //3-获取标题内容
        Row rowTitle = sheet.createRow(0);
        if (Objects.nonNull(rowTitle)) {
            int cellCount = rowTitle.getPhysicalNumberOfCells();

            for (int cellNum = 0; cellNum < cellCount; cellNum++) {
                Cell cell = rowTitle.getCell(cellNum);
                if (Objects.nonNull(cell)) {
                    int cellType = cell.getCellType();
                    String cellValue = cell.getStringCellValue();
                    System.out.println(cellValue + " | ");
                }
            }
            System.out.println();
        }


    }
}
